var data = [];
try {
	var ug = searchResults.usergroups;
	if (ug){
	for ( var i = 0; i < ug.length; i++) {
		var row = Ti.UI.createTableViewRow({height: 40});

		var nameLabel = Ti.UI.createLabel( {
			text : ug[i].Name,
			left : 5,
			top : 5,
			height : 16,
			right : 5,
			font: {fontSize:12, fontWeight:'bold'},
			color: '#fff'
		});
		row.add(nameLabel);

		var locationLabel = Ti.UI.createLabel( {
			text : ug[i].City + ', ' + ug[i].Region,
			left : 5,
			right: 100,
			height : 14,
			bottom: 5,
			font: {fontSize:10, fontWeight:'bold'},
			color: '#bb0'
		});		
		row.add(locationLabel);			
		
		//Location based searches show distance from current location
		if (searchResults.type=='location'){

			if (ug[i].Distance){
				
				var distanceLabel = Ti.UI.createLabel( {
					text : ug[i].Distance + ' miles',
					right: 5,
					width: 95,
					textAlign: 'right',
					height : 14,
					bottom: 5,
					font: {fontSize:10, fontWeight:'bold'},
					color: '#bbb'
				});		
				row.add(distanceLabel);
			}
		}
		row.className = 'search_row';
		row.usergroup = JSON.stringify(ug[i]);
		
		data.push(row);
	}
	}

	var tableview = Ti.UI.createTableView( {
		data : data,
		top: 10,
		left: 20,
		bottom: 40,
		right: 20,
		//width: viewScrollContainer.size.width,
		height: resultsPanel.size.height - 50,
		scrollable: true,
		separatorStyle: 0,
		separatorColor:'transparent' 
	});

	
	resultsPanel.add(tableview);

	tableview.addEventListener('click', function(e) {
		Ti.App.Properties.setString('ug_details', e.row.usergroup);
		
		var details = Ti.UI.createWindow({
		    backgroundImage:DotNetNuke.getBackgroundImage(),
		    navBarHidden: true,
		    orientationModes: Ti.UI.PORTRAIT,
		    url: 'usergroupdetails.js'
		});
		
		if (DotNetNuke.isAndroid()) {
			removeMapView();
		}
		details.open();		
	});
} catch (E) {
	alert(E);
}
